﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FuncCheckUseCase.cs" company="">
//   
// </copyright>
// <summary>
//   The func check use case.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.UseCases
{
    using System;

    /// <summary>
    ///   The func check use case.
    /// </summary>
    public class FuncCheckUseCase : CheckUseCase
    {
        #region Fields

        /// <summary>
        ///   The _get func.
        /// </summary>
        private readonly Func<bool> _getFunc;

        /// <summary>
        ///   The _set action.
        /// </summary>
        private readonly Action<bool> _setAction;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="FuncCheckUseCase"/> class.
        /// </summary>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <param name="service">
        /// The service. 
        /// </param>
        /// <param name="getFunc">
        /// The get func. 
        /// </param>
        /// <param name="setAction">
        /// The set action. 
        /// </param>
        public FuncCheckUseCase(
            ICompoundUseCase parent, IUseCaseInstanceService service, Func<bool> getFunc, Action<bool> setAction)
            : base(parent, service)
        {
            _getFunc = getFunc;
            _setAction = setAction;
        }

        #endregion

        #region Methods

        /// <summary>
        ///   The get value.
        /// </summary>
        /// <returns> The <see cref="bool" /> . </returns>
        protected override bool GetValue()
        {
            return _getFunc();
        }

        /// <summary>
        /// The set value.
        /// </summary>
        /// <param name="value">
        /// The value. 
        /// </param>
        protected override void SetValue(bool value)
        {
            _setAction(value);
            Modified = true;
        }

        #endregion
    }
}